package com.jcw.controller;

import com.jcw.common.R;
import com.jcw.domain.AddressBook;
import com.jcw.service.AddressBookService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/addressBook")
public class AddressBookController {

    @Resource
    private AddressBookService addressBookService;

    @GetMapping("/list")
    public R<List> listR(){
        return R.success(addressBookService.list());
    }

    @PutMapping("/default")
    public R<String> defaultAddr(@RequestBody AddressBook addressBook){
        return addressBookService.editDefault(addressBook);
    }

    @PostMapping
    public R<String> add(@RequestBody AddressBook addressBook){
        return addressBookService.add(addressBook);
    }

    @GetMapping("/{id}")
    public R<AddressBook> echo(@PathVariable Long id){
        return addressBookService.echoAddr(id);
    }

    @PutMapping
    public R<String> editAddr(@RequestBody AddressBook addressBook){
        return addressBookService.editAddr(addressBook);
    }

    @DeleteMapping
    public R<String> delete(String ids){
        return addressBookService.delete(ids);
    }

    @GetMapping("/default")
    public R<AddressBook> defaultAddr(){
        return addressBookService.defaultAddr();
    }
}
